from django.conf import settings

if not settings.MEDIA_URL:
  raise ValueError("You must define a MEDIA_URL in your django settings.py")

def reduce_url_parts(a, b):
    if a[-1] == "/":
        return a + b
    return a + "/" + b

def url_join(*args):
    return reduce(reduce_url_parts, args)

# relative to the root MEDIA_URL
WEBMAPPER_MEDIA_URL = getattr(settings, "WEBMAPPER_MEDIA_URL", url_join(settings.MEDIA_URL, "webmapper"))

WEBMAPPER_CSS_URL = url_join(WEBMAPPER_MEDIA_URL, "css")
WEBMAPPER_IMG_URL = url_join(WEBMAPPER_MEDIA_URL, "img")
WEBMAPPER_JS_URL = url_join(WEBMAPPER_MEDIA_URL, "js")

